package com.csjbot.blackgaga.base;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.csjbot.blackgaga.BuildConfig;
import com.csjbot.blackgaga.MainActivity;
import com.csjbot.blackgaga.R;
import com.csjbot.blackgaga.ai.BaseAI;
import com.csjbot.blackgaga.core.RobotManager;
import com.csjbot.blackgaga.feature.settings.SettingsActivity;
import com.csjbot.blackgaga.feature.settings.network.SettingsNetworkActivity;
import com.csjbot.blackgaga.global.Constants;
import com.csjbot.blackgaga.home.HomeActivity;
import com.csjbot.blackgaga.model.http.bean.LogoBean;
import com.csjbot.blackgaga.model.http.workstream.Logo;
import com.csjbot.blackgaga.model.tcp.factory.ServerFactory;
import com.csjbot.blackgaga.model.tcp.tts.ISpeak;
import com.csjbot.blackgaga.network.NetworkConstants;
import com.csjbot.blackgaga.speechrule.ChatControl;
import com.csjbot.blackgaga.util.BlackgagaLogger;
import com.csjbot.blackgaga.util.ConfInfoUtil;
import com.csjbot.blackgaga.util.EnglishChatHandle;
import com.csjbot.blackgaga.util.RichTextUtil;
import com.csjbot.blackgaga.util.SharedKey;
import com.csjbot.blackgaga.util.SharedPreUtil;
import com.csjbot.blackgaga.util.VolumeUtil;
import com.csjbot.blackgaga.widget.ChatView;
import com.csjbot.blackgaga.widget.NewRetailDialog;
import com.csjbot.blackgaga.widget.TitleView;
import com.csjbot.coshandler.listener.OnSpeakListener;
import com.csjbot.coshandler.log.CsjlogProxy;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import io.reactivex.Observer;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;

/**
 * Created by xiasuhuei321 on 2017/8/11.
 * author:luo
 * e-mail:xiasuhuei321@163.com
 */

public abstract class BaseFullScreenActivity extends BaseActivity {

    protected TitleView mTitleView;

    private ChatView mChatView;
    protected int mMode;
    private ISpeak mSpeak;

    protected Activity context;

    private NetworkReceiver receiver;

    boolean isResume = false;

    private AlertDialog dialog;

    private NewRetailDialog mDialog;

    private CsjlogProxy mLogProxy;

    private ChatControl mChatControl;

    protected boolean openNoNetworkDialog = true;

    @Override
    protected final void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        //隐藏标题栏
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //隐藏状态栏
        //定义全屏参数
        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        //获得当前窗体对象
        Window window = this.getWindow();
        //设置当前窗体为全屏显示
        window.setFlags(flag, flag);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//横屏
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        init();
        afterViewCreated(savedInstanceState);
    }


    @Override
    protected void onResume() {
        super.onResume();
        addSpeechListener();
        isResume = true;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(receiver);
        unregisterReceiver(updateLogoReceiver);
    }

    public abstract int getLayoutId();

    /**
     * 是否启用聊天窗口
     *
     * @return
     */
    public boolean isOpenChat() {
        return false;
    }

    /**
     * 是否启用Title
     *
     * @return
     */
    public boolean isOpenTitle() {
        return false;
    }

    /**
     * 不强制要求子类实现这个方法，你可以不初始化
     */
    public void init() {
        initTitle();
        initChat();
        initSpeak();

        BaseAI baseAI = BaseAI.newInstance();
        baseAI.initAI(this);
        receiver = new NetworkReceiver();
        IntentFilter intentFilter = new IntentFilter(NetworkConstants.SEND_ACTION);
        registerReceiver(receiver, intentFilter);
        IntentFilter logoFilter = new IntentFilter(Constants.UPDATE_LOGO);
        registerReceiver(updateLogoReceiver, logoFilter);

        initWelcomeSpeakText();

        initDialog();

        if (mLogProxy == null) {
            mLogProxy = CsjlogProxy.getInstance();
            mLogProxy.initLog(context);
        }

        mChatControl = ChatControl.newInstance(this);
        String initText = mChatControl.initChild();
        if(!TextUtils.isEmpty(initText)){
            prattle(initText);
        }

    }

    public ChatControl getChatControl(){
        return mChatControl;
    }

    public CsjlogProxy getLog() {
        return mLogProxy;
    }

    private void initDialog() {
        mDialog = new NewRetailDialog(this);
    }

    protected void showNewRetailDialog(String title, String text, NewRetailDialog.OnDialogClickListener listener) {
        if (mDialog != null) {
            mDialog.setTitle(title);
            mDialog.setContent(text);
            mDialog.setListener(listener);
            mDialog.show();
        }
    }

    protected void showNewRetailDialog(int title, int text, NewRetailDialog.OnDialogClickListener listener) {
        if (mDialog != null) {
            mDialog.setTitle(title);
            mDialog.setContent(text);
            mDialog.setListener(listener);
            mDialog.show();
        }
    }

    protected void showNewRetailDialog(String title, String text, String yes, String no, NewRetailDialog.OnDialogClickListener listener) {
        if (mDialog != null) {
            mDialog.setTitle(title);
            mDialog.setContent(text);
            mDialog.setYes(yes);
            mDialog.setNo(no);
            mDialog.setListener(listener);
            mDialog.show();
        }
    }

    protected void showNewRetailDialog(int title, int text, int yes, int no, NewRetailDialog.OnDialogClickListener listener) {
        if (mDialog != null) {
            mDialog.setTitle(title);
            mDialog.setContent(text);
            mDialog.setYes(yes);
            mDialog.setNo(no);
            mDialog.setListener(listener);
            mDialog.show();
        }
    }

    protected void dismissNewRetailDialog() {
        if (mDialog != null) {
            mDialog.dismiss();
        }
    }

    void initWelcomeSpeakText() {
        CharSequence text = "";
        switch (Constants.Language.CURRENT_LANGUAGE) {
            case Constants.Language.CHINESE:
                text = initChineseSpeakText();
                break;
            case Constants.Language.ENGELISH:
                text = initEnglishSpeakText();
                break;
            default:
                break;
        }
        if (TextUtils.isEmpty(text)) {
            return;
        }
        speak(text.toString());
        setRobotChatMsg(text);
    }

    protected CharSequence initChineseSpeakText() {
        return null;
    }

    protected CharSequence initEnglishSpeakText() {
        return null;
    }


    /**
     * 添加语音监听事件
     */
    private void addSpeechListener() {
        RobotManager.getInstance().addListener((json, type) -> {
            switch (type) {
                case 0:
                    try {
                        String text = new JSONObject(json).getString("text");

                        if (Constants.Language.isEnglish()) {
                            englishHandle(text);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    break;
                case 1:
                    try {
                        JSONObject result = new JSONObject(json).getJSONObject("result");
                        String text = result.getString("text");
                        runOnUiThread(() -> {
                            if (Constants.Language.isEnglish()) {
                                return;
                            }
                            if (!mSpeak.isSpeaking()) {
                                setCustomerChatMsg(text);
                            }
                        });

                        String service = "";
                        try{
                            service = result.getJSONObject("data").getString("service");
                        }catch(Exception ignored){
                        }

                        CsjlogProxy.getInstance().info("service:"+service);


                        String answerText = result.getJSONObject("answer").getString("answer_text");

                        if(answerText.contains("#$#$")){
                            String replaceName = "";
                            if(BuildConfig.robotType.equals(BuildConfig.ROBOT_TYPE_DEF_ALICE)){
                                replaceName = "爱丽丝";
                            }else if(BuildConfig.robotType.equals(BuildConfig.ROBOT_TYPE_DEF_SNOW)){
                                replaceName = "小雪";
                            }
                            answerText = answerText.replace("#$#$",replaceName);
                            CsjlogProxy.getInstance().info("answerText:"+answerText);
                        }
                        String filterText = answerText;

                        if(service.equals("CHAT")){
                            runOnUiThread(() -> onSpeechMessage(text, filterText));
                        }else{
                            runOnUiThread(() -> onSpeechMessage(text, filterText));
                        }
                    } catch (JSONException e) {
                        CsjlogProxy.getInstance().info("json解析出错");
                    }
                    break;
            }

        });
    }


    public void setRobotChatMsg(CharSequence text) {
        if (getChatView() != null && (!TextUtils.isEmpty(text))) {
            getChatView().addChatMsg(ChatView.ChatMsgType.ROBOT_MSG, text);
        }
    }

    public void setRobotChatMsg(@StringRes int stringId) {
        if (getChatView() != null) {
            getChatView().addChatMsg(ChatView.ChatMsgType.ROBOT_MSG, getString(stringId));
        }
    }

    public void setCustomerChatMsg(CharSequence text) {
        if (getChatView() != null && (!TextUtils.isEmpty(text))) {
            getChatView().addChatMsg(ChatView.ChatMsgType.CUSTOMER_MSG, text);
        }
    }

    public void setCustomerChatMsg(@StringRes int stringId) {
        if (getChatView() != null) {
            getChatView().addChatMsg(ChatView.ChatMsgType.CUSTOMER_MSG, getString(stringId));
        }
    }

    protected void englishHandle(String text) {
        if (!mSpeak.isSpeaking()) {
            runOnUiThread(() -> setCustomerChatMsg(text));

        }
        String answer = EnglishChatHandle.newInstance().getAnswer(text);
        speak(answer);
        runOnUiThread(() -> setRobotChatMsg(answer));

    }

    private boolean robotNameAnswer(String text){
        if(text.contains("你是谁")
                || text.contains("你叫什么名字")
                || text.contains("你叫什么")
                || text.contains("你叫啥")
                || text.contains("你是啥")){
            String answer = "";
            if(BuildConfig.robotType.equals(BuildConfig.ROBOT_TYPE_DEF_ALICE)){
                answer = "我叫爱丽丝,您问有什么可以帮您的吗?";
            }else if(BuildConfig.robotType.equals(BuildConfig.ROBOT_TYPE_DEF_SNOW)){
                answer = "我叫小雪,您问有什么可以帮您的吗?";
            }
            if(!TextUtils.isEmpty(answer)){
                prattle(answer);
            }
            return true;
        }
        return false;
    }

    protected boolean onSpeechMessage(String text, String answerText) {
        if (Constants.Language.isEnglish()) {
            return true;
        }


        // 机器人名称过滤拦截
        if(robotNameAnswer(text)){
            return true;
        }

        String result = mChatControl.handleGlobal(text);
        CsjlogProxy.getInstance().info("handleGlobal:result:"+result);
        if(!TextUtils.isEmpty(result)){
            if(!result.equals(ChatControl.ACTION)){
                prattle(result);
            }
            return true;
        }
        result = mChatControl.handleChild(text);
        CsjlogProxy.getInstance().info("handleChild:result:"+result);
        if(!TextUtils.isEmpty(result)){
            if(!result.equals(ChatControl.ACTION)){
                prattle(result);
            }
            return true;
        }

        return false;
    }

    protected void prattle(String answerText) {
        if (!mSpeak.isSpeaking()) {
            speak(answerText);
            setRobotChatMsg(answerText);
        }
    }


    private void initSpeak() {
        mSpeak = ServerFactory.getSpeakInstance();
    }

    private void initChat() {
        if (isOpenChat()) {
            mChatView = (ChatView) findViewById(R.id.chat_view);
        }
    }

    private void initTitle() {
        if (isOpenTitle()) {
            mTitleView = (TitleView) findViewById(R.id.title_view);
            initImage();
//            mTitleView.setLanguageImage(R.drawable.iv_language_ch);
            mTitleView.setLanguageText(R.string.language_text);
            mTitleView.setSetLanguageListener(() -> {
                Intent intent = new Intent();
                intent.setClass(BaseFullScreenActivity.this, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(MainActivity.STAY, true);
                startActivity(intent);
                finish();
//                overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
            });
            mTitleView.setCustomerServiceListener(() -> Toast.makeText(this, R.string.service, Toast.LENGTH_SHORT).show());
            mTitleView.setSettingsListener(() -> jumpActivity(SettingsActivity.class));
            mTitleView.setHomePageListener(() -> jumpActivity(HomeActivity.class));
            mTitleView.setBackListener(BaseFullScreenActivity.this::finish);
            mTitleView.setSettingsPageBackListener(BaseFullScreenActivity.this::finish);

            updateLogo();
        }
    }

    private void initImage() {
        mMode = SharedPreUtil.getInt(SharedKey.LANGUAGEMODE_NAME, SharedKey.LANGUAGEMODE_KEY, 1);
        switch (mMode) {
            case 0:
                mTitleView.setLanguageImage(R.drawable.language_en);
                break;
            case 1:
                mTitleView.setLanguageImage(R.drawable.iv_language_ch);
                break;
            case 2:
                mTitleView.setLanguageImage(R.drawable.language_jp);
                break;
            default:
                break;
        }

    }

    /**
     * 获取当前ChatView
     *
     * @return
     */
    public ChatView getChatView() {
        return mChatView;
    }

    /**
     * 获取当前TitleView
     *
     * @return
     */
    public TitleView getTitleView() {
        return mTitleView;
    }

    /**
     * 对于某些特殊的Activity，你可能需要重写这个方法拿到savedInstanceState
     * 来恢复一些状态
     *
     * @param savedInstanceState
     */
    public void afterViewCreated(Bundle savedInstanceState) {
    }


    /**
     * 根据传入的class进行activity的跳转
     *
     * @param c
     */
    public void jumpActivity(Class<? extends Activity> c) {
        if (c != null) {
            startActivity(new Intent(this, c));
        }
    }

    /**
     * 根据传入的class进行activity的跳转  可传入参数
     */
    public void jumpActivity(Class<? extends Activity> c, Bundle bundle) {
        if (c != null) {
            Intent intent = new Intent(this, c);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }

    /**
     * 提供说话功能
     *
     * @param text
     * @param listener
     */
    protected void speak(String text, OnSpeakListener listener) {
        if (!TextUtils.isEmpty(text)) {
            mSpeak.startSpeaking(text, listener);
        }
    }

    protected void speak(String text, boolean isSetRobotChatMsg) {
        speak(text, null, isSetRobotChatMsg);
    }

    protected void speak(String text, OnSpeakListener listener, boolean isSetRobotChatMsg) {
        speak(text, listener);
        if (isSetRobotChatMsg) {
            setRobotChatMsg(text);
        }
    }

    protected void speak(@StringRes int stringId, OnSpeakListener listener, boolean isSetRobotChatMsg) {
        speak(getString(stringId), listener, isSetRobotChatMsg);
    }

    protected void speak(@StringRes int stringId, OnSpeakListener listener) {
        speak(getString(stringId), listener, false);
    }

    /**
     * 重新dispatchTouchEvent方法
     *
     * @param ev
     * @return
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideKeyboard(v, ev)) {
                hideKeyboard(v.getWindowToken());
            }
        }
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 根据EditText所在坐标和用户点击的坐标相对比，来判断是否隐藏键盘，因为当用户点击EditText时则不能隐藏
     *
     * @param v
     * @param event
     * @return
     */
    private boolean isShouldHideKeyboard(View v, MotionEvent event) {
        if (v != null && (v instanceof EditText)) {
            int[] l = {0, 0};
            v.getLocationInWindow(l);
            int left = l[0],
                    top = l[1],
                    bottom = top + v.getHeight(),
                    right = left + v.getWidth();
            return !(event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom);
        }
        // 如果焦点不是EditText则忽略，这个发生在视图刚绘制完，第一个焦点不在EditText上，和用户用轨迹球选择其他的焦点
        return false;
    }

    /**
     * 获取InputMethodManager，隐藏软键盘
     *
     * @param token
     */
    private void hideKeyboard(IBinder token) {
        if (token != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 提供说话功能
     *
     * @param text
     */
    public void speak(String text) {
        if (!TextUtils.isEmpty(text)) {
            mSpeak.startSpeaking(text, null);
        }

    }

    public void speak(@StringRes int stringId) {
        speak(getString(stringId), null, false);
    }

    protected void speak(@StringRes int stringId, boolean isSetRobotChatMsg) {
        speak(getString(stringId), null, isSetRobotChatMsg);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mSpeak.isSpeaking()) {
            mSpeak.stopSpeaking();
        }
        isResume = false;
    }

    public void stopSpeak() {
        if (mSpeak.isSpeaking()) {
            mSpeak.stopSpeaking();
        }
    }

    /**
     * 给定关键字，文本将高亮标出关键字，如果传入点击监听，在点击相应的关键字时将会调用监听事件。同一个关键字，如 "周边"
     * 全文中的 "周边" 关键字都会被高亮标出，但是只会不论点击哪一个 "周边" 关键字，调用的都是同一个事件。
     *
     * @param talkText 原文字
     * @param keyword  关键字
     * @param color    高亮颜色
     * @return 处理后的字符
     */
    protected CharSequence getColorfulText(String talkText, String keyword, int color) {
        return RichTextUtil.getColorString(talkText, keyword, color);
    }

    /**
     * 给定关键字，文本将高亮标出关键字，如果传入点击监听，在点击相应的关键字时将会调用监听事件。同一个关键字，如 "周边"
     * 全文中的 "周边" 关键字都会被高亮标出，但是只会不论点击哪一个 "周边" 关键字，调用的都是同一个事件。
     *
     * @param talkText 原文字
     * @param keyword  关键字
     * @param color    高亮颜色
     * @param listener 点击监听
     * @return
     */
    protected CharSequence getColorfulText(String talkText, String keyword, int color, View.OnClickListener listener) {
        return RichTextUtil.getColorString(talkText, keyword, color, listener);
    }

    /**
     * 给定关键字，文本将高亮标出关键字，如果传入点击监听，在点击相应的关键字时将会调用监听事件。同一个关键字，如 "周边"
     * 全文中的 "周边" 关键字都会被高亮标出，但是只会不论点击哪一个 "周边" 关键字，调用的都是同一个事件。
     *
     * @param talkText 原文字
     * @param keywords 关键字集合
     * @param colorMap 关键字对应的高亮颜色Map
     * @return
     */
    protected CharSequence getColorfulText(String talkText, List<String> keywords, Map<String, Integer> colorMap) {
        return RichTextUtil.getColorString(talkText, keywords, colorMap);
    }

    /**
     * 给定关键字，文本将高亮标出关键字，如果传入点击监听，在点击相应的关键字时将会调用监听事件。同一个关键字，如 "周边"
     * 全文中的 "周边" 关键字都会被高亮标出，但是只会不论点击哪一个 "周边" 关键字，调用的都是同一个事件。
     *
     * @param talkText    原文字
     * @param keywords    关键字集合
     * @param colorMap    关键字对应的高亮颜色Map
     * @param listenerMap 关键字对应的点击事件Map
     * @return
     */
    protected CharSequence getColorfulText(String talkText, List<String> keywords, Map<String, Integer> colorMap, Map<String, View.OnClickListener> listenerMap) {
        return RichTextUtil.getColorString(talkText, keywords, colorMap, listenerMap);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    public class NetworkReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (!isResume) {
                return;
            }

            int state = intent.getIntExtra(NetworkConstants.NET_WORK_STATE, NetworkConstants.NETWORK_UNAVAILABLE);
            if (state == NetworkConstants.NETWORK_AVAILABLE) {
                BlackgagaLogger.debug("网络可用");
                if (dialog != null && dialog.isShowing()) dialog.dismiss();
                networkAvailability();
                if (Logo.isFirst) {
                    Logo.isFirst = true;
                    Logo.getLogo(ConfInfoUtil.getSN(), new Observer<LogoBean>() {
                        @Override
                        public void onSubscribe(@NonNull Disposable d) {

                        }

                        @Override
                        public void onNext(@NonNull LogoBean logoBean) {
                            Logo.setLogoBean(logoBean);
                            if (isOpenTitle()) {
                                mTitleView.setLogo(R.drawable.new_logo);
                                if (logoBean == null) {
                                    BlackgagaLogger.debug("logo为空，使用默认logo");
                                    mTitleView.setLogo(R.drawable.new_logo);
                                } else {
                                    if (logoBean.getType() == LogoBean.TYPE_LOCAL) {
                                        BlackgagaLogger.debug("有logo但是使用本地logo");
                                        mTitleView.setLogo(R.drawable.new_logo);
                                    } else {
                                        BlackgagaLogger.debug("加载网络logo");
                                        mTitleView.setLogo(logoBean.getResult().get(0).getLogourl());
                                    }
                                }
                            }
                        }

                        @Override
                        public void onError(@NonNull Throwable e) {

                        }

                        @Override
                        public void onComplete() {

                        }
                    });
                }
            } else {
                networkUnavailable();
                BlackgagaLogger.debug("网络不可用");
                showNewRetailDialog(getString(R.string.net_work_nouse), getString(R.string.network_unavailable),
                        getString(R.string.sure), getString(R.string.cancel), new NewRetailDialog.OnDialogClickListener() {
                            @Override
                            public void yes() {
                                startActivity(new Intent(BaseFullScreenActivity.this, SettingsNetworkActivity.class));
                                dismissNewRetailDialog();
                            }

                            @Override
                            public void no() {
                                dismissNewRetailDialog();
                            }
                        });
            }
        }
    }

    public void networkAvailability() {
        // 重新打开语音识别服务
        ServerFactory.getSpeechInstance().startIsr();
    }

    public void networkUnavailable() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
                VolumeUtil.addMediaVolume(this);
                return true;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                VolumeUtil.cutMediaVolume(this);
                return true;
            default:
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void updateLogo() {
        if (isOpenTitle()) {
            LogoBean logo = Logo.getLogo();
            if (logo == null) {
                BlackgagaLogger.debug("logo为空，使用默认logo");
                if (TextUtils.isEmpty(Logo.getDefaultUrl())) {
                    mTitleView.setLogo(R.drawable.new_logo);
                } else {
                    mTitleView.setLogo(Logo.getDefaultUrl());
                }
            } else {
                if (logo.getType() == LogoBean.TYPE_LOCAL) {
                    BlackgagaLogger.debug("有logo但是使用本地logo");
                    mTitleView.setLogo(R.drawable.new_logo);
                } else {
                    BlackgagaLogger
                            .debug("加载网络logo");
                    mTitleView.setLogo(logo.getResult().get(0).getLogourl());
                }
            }
        }
    }

    private BroadcastReceiver updateLogoReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateLogo();
        }
    };


}
